/************************************************************************/
/*  									*/
/*  writecdwd_MI.c							*/
/*									*/
/*  Tom Lookabaugh							*/
/*  August 14, 1987							*/
/*  Last Revision: August 14, 1987					*/
/*									*/
/*  DESCRIPTION								*/
/*	Modified Itakura and Modified Itakura-Saito versions.		*/
/*	Writes the reflection coefficients associated with a codeword.	*/
/*  RETURNS								*/
/*	No significant value.  						*/
/*  CALLS								*/
/*	error()								*/
/*									*/
/************************************************************************/

#include "stdvq.h"
#include <math.h>

writecdwd (cdbk, cdwd, dist, tsvect, cdbksz, outfile) 

    double *cdbk;	/* codebook					*/
    int cdwd;		/* index of desired codeword			*/
    double dist;	/* best distortion				*/
    double* tsvect;	/* current test sequence vector			*/
    int cdbksz;		/* size of codebook				*/
    FILE *outfile;	/* output file					*/
    
{
    double gain;	/* gain for encoding by scalar Itakura-Saito	*/
    
    gain = tsvect[0]*exp(dist);

    if (fwrite(&gain, sizeof(double), 1, outfile) != 1) 
      error("failed to write gain (writecdwd 1)");
    if (fwrite(cdbk + cdbksz*cdbkdim + cdwd*(dim - 2), sizeof(double),
      dim - 2, outfile) != dim - 2) 
      error("failed to write codeword (writecdwd 2)");


}
